package main

import (
	"os"
	"runtime"
	"zcommom/commom"
	"zcommom/install"
	"zcommom/zlog"
)

type Config struct {
	Name, DisplayName, Description string
}
type startPram struct{}

func (s startPram) OnStart() {
	defer close()

	select {}
}
func (s startPram) OnStop() {
	zlog.Info("OnStop")
}

func close() {
	if r := recover(); r != nil {
		buff := make([]byte, 1<<10)
		runtime.Stack(buff, false)
		zlog.Error(r, string(buff))
		//fmt.Printf("%v %v", r, string(buff))
	}
}

func main() {
	arg := ""
	//是通过systemctl start |stop
	if len(os.Args) > 1 {
		arg = os.Args[1]
	}

	if arg == "" {
		//需要把日志输出到控制台，不是在日志文件
		zlog.SetFmt()
	} else {
		appPath := commom.GetAppPath()
		zlog.SetLogFile(appPath+"/log", ".log")
		zlog.CheckMaxLog(7)
	}

	config := Config{Name: "ycrons", DisplayName: "ycrons 定时任务", Description: "ycrons 定时任务"}
	s := startPram{}
	install.Run(config.Name, config.DisplayName, config.Description, s)
}
